package com.movie.controller;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


import com.movie.beans.ReviewBeans;
import com.movie.dao.ReviewDao;

public class ReviewAction implements Action{
	int type;
	ReviewBeans rb = new ReviewBeans();
	ReviewDao rd = new ReviewDao();
	public ReviewAction(int type){
		this.type=type;
		
	}
	public Forward execute(HttpServletRequest request, HttpServletResponse response){
		Forward forward = new Forward();
		if(type==0){
			
			HttpSession session = request.getSession();
			String id = session.getAttribute("id").toString();
			ArrayList<ReviewBeans> list = new ArrayList<ReviewBeans>();
			System.out.println(id);
			list = rd.viewReview(id);
			
			String html=makeHTML1(list); 
			System.out.println("액션"+html);
			request.setAttribute("html",html);
			
			forward.setPagePath("./main.jsp?page=myMovieStory");
			forward.setRedirect(false);
		}
		return forward;
	}
	public void writeReview(){
		
	}
	public void modifyReview(){
		
	}
	public void deleteReview(){
		
	}
	public void searchReview(){
		
	}

	public void viewReview() {

	}

	public String makeHTML1(ArrayList<ReviewBeans> list) {
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < list.size(); i++) {
			sb.append("<div id = 'ms_c2'><div id = 'ms_c3' class = 'border lfloat'><img src ="
					+ list.get(i).getImage()
					+ "></div><div id = 'ms_c4' class = 'border rfloat'>"
					+ "영화제목 : "+ list.get(i).getMvname()+"<br>"
					+ "관람일 : "+ list.get(i).getMdate()+"<br>"
					+ "영화관 : "+ list.get(i).getTname()+"<br>"
					+ "명대사 : "+ list.get(i).getSpeech()+"<br>"
					+ "작성일 : "+ list.get(i).getRdate()+"<br>"
					+ "감상평 : "+ list.get(i).getReport()+"<br>"
					+ "평점 : "+ list.get(i).getSpoint()+"<br>"
					+"</div></div><div class = 'height20'></div><div class = 'height20'></div>");
		}
		return sb.toString();

	}
	
}
